#include "st7789.h"

void init_st7789(void)
{
ST7789_WriteCommand(0x36);     
ST7789_WriteSmallData(0x00);   

ST7789_WriteCommand(0x3A);     
ST7789_WriteSmallData(0x55);   

ST7789_WriteCommand(0xB2);     
ST7789_WriteSmallData(0x0C);   
ST7789_WriteSmallData(0x0C);   
ST7789_WriteSmallData(0x00);   
ST7789_WriteSmallData(0x33);   
ST7789_WriteSmallData(0x33);   

ST7789_WriteCommand(0xB7);     
ST7789_WriteSmallData(0x46);   //VGH=13.65V,VGL=-11.38V

ST7789_WriteCommand(0xBB);     
ST7789_WriteSmallData(0x1B);   

ST7789_WriteCommand(0xC0);     
ST7789_WriteSmallData(0x2C);   

ST7789_WriteCommand(0xC2);     
ST7789_WriteSmallData(0x01);   

ST7789_WriteCommand(0xC3);     
ST7789_WriteSmallData(0x0F);   

ST7789_WriteCommand(0xC4);     
ST7789_WriteSmallData(0x20);   

ST7789_WriteCommand(0xC6);     
ST7789_WriteSmallData(0x0F);   

ST7789_WriteCommand(0xD0);     
ST7789_WriteSmallData(0xA4);   
ST7789_WriteSmallData(0xA1);   

ST7789_WriteCommand(0xD6);     
ST7789_WriteSmallData(0xA1); 

ST7789_WriteCommand(0xE0);
ST7789_WriteSmallData(0xF0);
ST7789_WriteSmallData(0x00);
ST7789_WriteSmallData(0x06);
ST7789_WriteSmallData(0x04);
ST7789_WriteSmallData(0x05);
ST7789_WriteSmallData(0x05);
ST7789_WriteSmallData(0x31);
ST7789_WriteSmallData(0x44);
ST7789_WriteSmallData(0x48);
ST7789_WriteSmallData(0x36);
ST7789_WriteSmallData(0x12);
ST7789_WriteSmallData(0x12);
ST7789_WriteSmallData(0x2B);
ST7789_WriteSmallData(0x34);

ST7789_WriteCommand(0xE1);
ST7789_WriteSmallData(0xF0);
ST7789_WriteSmallData(0x0B);
ST7789_WriteSmallData(0x0F);
ST7789_WriteSmallData(0x0F);
ST7789_WriteSmallData(0x0D);
ST7789_WriteSmallData(0x26);
ST7789_WriteSmallData(0x31);
ST7789_WriteSmallData(0x43);
ST7789_WriteSmallData(0x47);
ST7789_WriteSmallData(0x38);
ST7789_WriteSmallData(0x14);
ST7789_WriteSmallData(0x14);
ST7789_WriteSmallData(0x2C);
ST7789_WriteSmallData(0x32);

ST7789_WriteCommand(0x21);  
}

void  init_ili9341(void)
{
	
		//POWER CONTROL A
	ST7789_WriteCommand(0xCB);
	ST7789_WriteSmallData(0x39);
	ST7789_WriteSmallData(0x2C);
	ST7789_WriteSmallData(0x00);
	ST7789_WriteSmallData(0x34);
	ST7789_WriteSmallData(0x02);

	//POWER CONTROL B
	ST7789_WriteCommand(0xCF);
	ST7789_WriteSmallData(0x00);
	ST7789_WriteSmallData(0xC1);
	ST7789_WriteSmallData(0x30);

	//DRIVER TIMING CONTROL A
	ST7789_WriteCommand(0xE8);
	ST7789_WriteSmallData(0x85);
	ST7789_WriteSmallData(0x00);
	ST7789_WriteSmallData(0x78);

	//DRIVER TIMING CONTROL B
	ST7789_WriteCommand(0xEA);
	ST7789_WriteSmallData(0x00);
	ST7789_WriteSmallData(0x00);

	//POWER ON SEQUENCE CONTROL
	ST7789_WriteCommand(0xED);
	ST7789_WriteSmallData(0x64);
	ST7789_WriteSmallData(0x03);
	ST7789_WriteSmallData(0x12);
	ST7789_WriteSmallData(0x81);

	//PUMP RATIO CONTROL
	ST7789_WriteCommand(0xF7);
	ST7789_WriteSmallData(0x20);

	//POWER CONTROL,VRH[5:0]
	ST7789_WriteCommand(0xC0);
	ST7789_WriteSmallData(0x23);

	//POWER CONTROL,SAP[2:0];BT[3:0]
	ST7789_WriteCommand(0xC1);
	ST7789_WriteSmallData(0x10);

	//VCM CONTROL
	ST7789_WriteCommand(0xC5);
	ST7789_WriteSmallData(0x3E);
	ST7789_WriteSmallData(0x28);

	//VCM CONTROL 2
	ST7789_WriteCommand(0xC7);
	ST7789_WriteSmallData(0x86);

	//MEMORY ACCESS CONTROL
	ST7789_WriteCommand(0x36);
	ST7789_WriteSmallData(0x48);

	//PIXEL FORMAT
	ST7789_WriteCommand(0x3A);
	ST7789_WriteSmallData(0x55);

	//FRAME RATIO CONTROL, STANDARD RGB COLOR
	ST7789_WriteCommand(0xB1);
	ST7789_WriteSmallData(0x00);
	ST7789_WriteSmallData(0x18);

	//DISPLAY FUNCTION CONTROL
	ST7789_WriteCommand(0xB6);
	ST7789_WriteSmallData(0x08);
	ST7789_WriteSmallData(0x82);
	ST7789_WriteSmallData(0x27);

	//3GAMMA FUNCTION DISABLE
	ST7789_WriteCommand(0xF2);
	ST7789_WriteSmallData(0x00);

	//GAMMA CURVE SELECTED
	ST7789_WriteCommand(0x26);
	ST7789_WriteSmallData(0x01);

	//POSITIVE GAMMA CORRECTION
	ST7789_WriteCommand(0xE0);
	ST7789_WriteSmallData(0x0F);
	ST7789_WriteSmallData(0x31);
	ST7789_WriteSmallData(0x2B);
	ST7789_WriteSmallData(0x0C);
	ST7789_WriteSmallData(0x0E);
	ST7789_WriteSmallData(0x08);
	ST7789_WriteSmallData(0x4E);
	ST7789_WriteSmallData(0xF1);
	ST7789_WriteSmallData(0x37);
	ST7789_WriteSmallData(0x07);
	ST7789_WriteSmallData(0x10);
	ST7789_WriteSmallData(0x03);
	ST7789_WriteSmallData(0x0E);
	ST7789_WriteSmallData(0x09);
	ST7789_WriteSmallData(0x00);

	//NEGATIVE GAMMA CORRECTION
	ST7789_WriteCommand(0xE1);
	ST7789_WriteSmallData(0x00);
	ST7789_WriteSmallData(0x0E);
	ST7789_WriteSmallData(0x14);
	ST7789_WriteSmallData(0x03);
	ST7789_WriteSmallData(0x11);
	ST7789_WriteSmallData(0x07);
	ST7789_WriteSmallData(0x31);
	ST7789_WriteSmallData(0xC1);
	ST7789_WriteSmallData(0x48);
	ST7789_WriteSmallData(0x08);
	ST7789_WriteSmallData(0x0F);
	ST7789_WriteSmallData(0x0C);
	ST7789_WriteSmallData(0x31);
	ST7789_WriteSmallData(0x36);
	ST7789_WriteSmallData(0x0F);
}


